{include file="public/header" /}
<link rel="stylesheet" href="__ORG__/validform/css/validform.css">
<script type="text/javascript" src="__ORG__/validform/js/Validform_v5.3.2_min.js"></script>
<link rel="stylesheet" type="text/css" href="__ORG__/uploadify/uploadify.css">
<script src="__ORG__/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<style type="text/css">
    .edui-default{line-height: 28px;}
    div.edui-combox-body,div.edui-button-body,div.edui-splitbutton-body
    {overflow: hidden; height:20px;}
    div.edui-box{overflow: hidden; height:22px;}

    .uploadify{display:inline-block;}
    .uploadify-button{border:none; border-radius:5px; margin-top:8px;}
    table.add_tab tr td span.uploadify-button-text{color: #FFF; margin:0;}
</style>

<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">


<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!--面包屑导航 开始-->
<div class="crumb_warp">
    <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
    <i class="fa fa-home"></i> <a href="{:url('admin/index/info')}">首页</a> &raquo; <a href="{:url('admin/book/index')}">图书管理</a> &raquo; 添加图书
</div>
<!--面包屑导航 结束-->

<!--结果集标题与导航组件 开始-->
<div class="result_wrap">
    <div class="result_title">
        <h3>图书管理操作</h3>
        {if isset($error)}
            <div class="mark">
                <p>{$error}</p>
            </div>
        {/if}
    </div>
    <div class="result_content">
        <div class="short_wrap">
            <a href="{:url('admin/book/add')}"><i class="fa fa-plus"></i>添加图书</a>
            <a href="{:url('admin/book/index')}"><i class="fa fa-recycle"></i>图书列表</a>
        </div>
    </div>
</div>
<!--结果集标题与导航组件 结束-->

<div class="result_wrap">
    <form action="" method="post" class="demoform">
        <table class="add_tab">
            <tbody>
            <tr>
                <th><i class="require">*</i>名称：</th>
                <td>
                    <input type="text" class="lg inputxt" name="title" placeholder="这里输入2到30位名称">
                </td>
            </tr>
            <tr>
                <th><i class="require">*</i>作者：</th>
                <td>
                    <input type="text" class="lg inputxt" name="author" placeholder="这里输入作者名称">
                    <span></span>
                </td>
            </tr>
            <tr>
                <th height="auto"><i class="require">*</i>图书分类</th>
                <td>
                    <select name="category_id" id="">
                        <!--<option value="">请选择图书栏目</option>-->
                        {foreach name="list" item="v"}
                        <option value="{$v->id}">{$v->html}{$v->name}</option>
                        {/foreach}
                    </select>
                </td>
            </tr>

            <tr>
                <th><i class="require"></i>图书缩略图：</th>
                <td>
                    <img id="thumb_url_img" src="" alt="" style="max-width: 300px; max-height: 100px;">
                    <input type="hidden" class="" size="50" name="thumb_url" value="" >
                    <input type="file" id="file_upload" />
                    <!--<p></p>-->
                </td>
            </tr>

            <tr>
                <th><i class="require">*</i>上传图书：</th>
                <td>
                    <input type="text" class="inputxt" size="30" name="book_url" value="" />
                    <input type="file" id="book_upload" />
                    <span>(图书必须为txt文件，且为 UTF-8 编码)</span>
                </td>
            </tr>

            <tr>
                <th><i class="require">*</i>图书描述：</th>
                <td>
                    <textarea title="图书描述" name="description" style="width:800px;height:150px;" nullmsg="请输入图书描述"></textarea>
                </td>
            </tr>

            <tr>
                <th></th>
                <td>
                    <input type="submit" value="提交">
                    <input type="button" class="back" onclick="history.go(-1)" value="返回">
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>
<script type="text/javascript">
    $(function() {
        var url = '{:url("/admin/common/upload/")}';
        $('#file_upload').uploadify({
            'formData'     : {
                'timestamp' : '<?php echo time();?>'
            },
            'buttonText' : '上传图片',
            'swf'      : '__ORG__/uploadify/uploadify.swf',
            'uploader' : url,
            'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
            },
            'onUploadSuccess' : function(file, data, response) {
                var datap = JSON.parse(data); //$.parseJSON(data);
                layer.msg(datap.msg);
                if(datap.errno == 0) {
                    $("input[name='thumb_url']").val(datap.path);
                    $('#thumb_url_img').attr('src', datap.path);
                }
            }
        });

        $('#book_upload').uploadify({
            'formData'     : {
                'timestamp' : '<?php echo time();?>'
            },
            'buttonText' : '上传图书',
            'swf'      : '__ORG__/uploadify/uploadify.swf',
            'uploader' : url + 'type/book',
            'onUploadError' : function(file, errorCode, errorMsg, errorString) {
                alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
            },
            'onUploadSuccess' : function(file, data, response) {
                var datap = JSON.parse(data); //$.parseJSON(data);
                layer.msg(datap.msg);
                if(datap.errno == 0) {
                    $("input[name='book_url']").val(datap.path);
                }
            }
        });
    });

    var demo=$(".demoform").Validform({
        tiptype:3,
        label:".label",
        showAllError:true,
        datatype:{
            "zh1-6":/^[\u4E00-\u9FA5\uf900-\ufa2d]{1,6}$/
        },
        ajaxPost:false
    });

    //通过$.Tipmsg扩展默认提示信息;
    //$.Tipmsg.w["zh1-6"]="请输入1到6个中文字符！";
    demo.tipmsg.w["zh1-6"]="请输入1到6个中文字符！";
    demo.tipmsg.w["*2-20"]="图书标题请输入2到30个字符！";
    demo.tipmsg.w["*3-50"]="图书缩略图不能为空！";

    demo.addRule([{
            ele:".inputxt:eq(0)",
            datatype:"*2-30"
        },
        {
            ele:".inputxt:eq(1)",
            datatype:"*2-30"
        },
        {
            ele:".inputxt:eq(2)",
            datatype:"*"
        },
        {
            ele:"select",
            datatype:"*"
        },
        {
            ele:"textarea",
            datatype:"*"
        }
        ]);

</script>
{include file="public/footer" /}